package com.xbongbong.schedule.util;

import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.saas.constant.BasicConstant;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 系统环境变量帮助类
 * 由于包配置问题，复制自 com.xbongbong.sys.help.SysEnvHelp 使用
 * @author zheng.li
 */
@Component
public class SystemEnvHelp {

    @Resource
    private ProBaseConfig proBaseConfig;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 是否灰度
     *
     * @return true:是 fasle:否
     */
    public boolean isGrayEnvironment() {
        return Objects.equals(proBaseConfig.getGray(), BasicConstant.GRAY_FLAG);
    }


    /**
     * Description: 判断公司是否在灰度（redis缓存）
     * @param corpid
     * @return boolean
     * @throws
     * @author 魏荣杰
     * @date 2022/6/16 11:16
     * @since
     */
    public boolean checkIsCrayCompany(String corpid) {
        String key = "ab:policies:0:divdata";
        String value = (String) stringRedisTemplate.opsForHash().get(key, corpid);
        return Objects.equals(value, "serverB");
    }


}
